package com.ipt.frm.pw;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ipt.frm.pw.listener.ContextListener;

/**
 * Servlet implementation class LogoutServlet
 */
public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	// Mensajes enviados por request para mostrar al usuario
	static final String MSG = "MSG";

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public LogoutServlet() {
		super();
	}

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		session.invalidate();
		ContextListener config = ContextListener
				.getInstance(getServletContext());
		String msg = config.getProperty("servlet.logout.ok");
		request.setAttribute(MSG, new Mensaje(TipoMensaje.EXITO, msg));
		request.getRequestDispatcher("/login.jsp").forward(request, response);
	}

}
